package springboot.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
@Configuration
public class LoginInterceptor implements HandlerInterceptor {
	//在请求之前进行调用
	public boolean preHandle(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,Object o)throws Exception{
		HttpSession session=httpServletRequest.getSession();
		if (session.getAttribute("user")!=null) {
			return true;
		}else {
			httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/");
			return false;	
		}
	}
}
